require 'Common/define'
require 'Logic/Config'
require 'Common/functions'

UICharactorInfoHeroSkillSelectItem = {};
HelperFunc.SetUIEnv(UICharactorInfoHeroSkillSelectItem)
local this = UICharactorInfoHeroSkillSelectItem;
this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;


this.imgSkillIcon = nil;
this.imgHeadIcon = nil;
this.txtSkillName = nil;
this.selectGo = nil
this.bgBtn = nil
function UICharactorInfoHeroSkillSelectItem.Init()--todo 应该小写 暂时先大写
    local name = getUIName(PanelNames.UICharactorInfoHeroSkillSelectItem);
    panelMgr:ShowUI(name, this.onCreate, Config.useLocalUI);
end

function UICharactorInfoHeroSkillSelectItem.onCreate()
    obj:SetActive(false);
end
---@param obj FairyGUI.GComponent
function UICharactorInfoHeroSkillSelectItem.initData(obj, data, selectCallback,itemCallback)
   -- LuaBehaviour = luaBehaviour;
    --gameObject = obj;
    --transform = obj.transform;
    bgBtn = obj:GetChild("BgBtn")
    imgSkillIcon = obj:GetChild("SkillIcon")
    local icon = imgSkillIcon:GetChild("icon")
    imgHeadIcon = obj:GetChild("HeadIcon")
    txtSkillName = obj:GetChild("SkillName")
    selectGo = obj:GetChild("SelectObj")
    local curSkillData = data["skill"];
    local iconName = tostring(curSkillData["f_SkillIcon"]);
    icon.url = "ui://SkillAtlas/"..iconName
    --resMgr:LoadIconFromPrefab("skillAtlas",iconName,function (sp)
    --    imgSkillIcon.sprite = sp;
   -- end);
    local curHeroData =data["hero"];
    imgHeadIcon.url = "ui://ICONAtlas/"..curHeroData.icon
    --resMgr:LoadIconFromPrefab("ICONAtlas",curHeroData.icon,function(sp)
    --    imgHeadIcon.sprite = sp;
    --end);

    txtSkillName.text =getLanguage(curSkillData["f_SkillName"]);
    imgSkillIcon.onClick:Clear()
    bgBtn.onClick:Clear()
    LuaBehaviour:AddClick(imgSkillIcon,
            function()
                if  itemCallback then
                    itemCallback(data)
                end
            end);
    LuaBehaviour:AddClick(bgBtn,
            function()
                if selectCallback then
                    selectCallback(data)
                end
            end);
end


function UICharactorInfoHeroSkillSelectItem.select(obj,flag)
    local selectmark = obj:GetChild("SelectObj");
    --selectmark:SetActive(flag);
    selectmark.visible = flag
end


return UICharactorInfoHeroSkillSelectItem;
